package com.yc.http.v1.impl;

import com.yc.http.v1.HttpSession;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class HttpSessionImpl implements HttpSession {

    private final long creationTime;
    private String id;
    private Map<String,Object> attributeMap = new HashMap<>();

    public HttpSessionImpl() {
        this.creationTime = System.currentTimeMillis();
        //初始化最后访问时间
        this.lastAccessedTime = System.currentTimeMillis();
        id = UUID.randomUUID().toString().replaceAll("-","");
    }

    @Override
    public long getCreationTime() {
        return creationTime;
    }
    @Override
    public String getId() {
        return id;
    }

    //最后访问时间
    long lastAccessedTime;
    @Override
    public long getLastAccessedTime() {
        return lastAccessedTime;
    }

    @Override
    public int getMaxInactiveInterval() {
        return 0;
    }

    @Override
    public void invalidate() {

    }

    @Override
    public void setAttribute(String name, Object value) {
        attributeMap.put(name,value);
    }

    @Override
    public Object getAttribute(String name) {
        return attributeMap.get(name);
    }

    @Override
    public void removeAttribute(String name) {
        attributeMap.remove(name);
    }
}
